package _21_多线程._1114_按序打印;

import java.util.concurrent.CountDownLatch;

public class _1114_按序打印_CountDownLatch {

    private final CountDownLatch second = new CountDownLatch(1);

    private final CountDownLatch three = new CountDownLatch(1);

    public _1114_按序打印_CountDownLatch() {
    }

    public void first(Runnable printFirst) throws InterruptedException {
        printFirst.run();
        second.countDown();
    }

    public void second(Runnable printSecond) throws InterruptedException {
        second.await();
        // printSecond.run() outputs "second". Do not change or remove this line.
        printSecond.run();
        three.countDown();
    }

    public void third(Runnable printThird) throws InterruptedException {
        three.await();
        // printSecond.run() outputs "second". Do not change or remove this line.
        printThird.run();
    }

}
